<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Order;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class OrderController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Order('user'), function (Grid $grid) {
            $grid->column('id')->sortable();
            //$grid->column('goods_id');
            $grid->column('user.nickname','用户');
            $grid->column('order_price');
            //$grid->column('goods_price');
            $grid->column('freight_price');
            $grid->column('stock_id');
            $grid->column('goods_name');
            $grid->column('order_number');
            $grid->column('order_status','订单状态')->options((new Order())->orderStatus());
            $grid->column('goods_cove')->image('',50,50);
            $grid->column('is_grant','是否发券');
            $grid->column('coupon_id');
            $grid->column('created_at');
            //$grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Order('user'), function (Show $show) {
            $show->field('id');
            $show->field('goods_id','商品ID');
            $show->field('user.nickname','用户');
            $show->field('order_price','金额');
            //$show->field('goods_price');
            $show->field('freight_price','运费');
            $show->field('stock_id');
            $show->field('goods_name');
            $show->field('order_number');
            $show->field('order_status','订单状态');
            $show->field('goods_cove')->image();
            $show->field('is_grant','是否发券');
            $show->field('coupon_id');
            $show->field('created_at');
            //$show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Order(), function (Form $form) {
            $form->display('id');
            $form->text('goods_id');
            $form->text('user_id');
            $form->text('order_price');
            $form->text('goods_price');
            $form->text('freight_price');
            $form->text('stock_id');
            $form->text('goods_name');
            $form->text('order_number');
            $form->text('order_status');
            $form->text('goods_cove');
            $form->text('is_grant');
            $form->text('coupon_id');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
